//
//  SFMainTabBarController.swift
//  SFWeiBo
//
//  Created by 孙凡 on 16/4/7.
//  Copyright © 2016年 Edward. All rights reserved.
//

import UIKit

class SFMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabbar = SFMainTabBar()


        //需要解决循环引用
//        weak var weakSelf = self
        //或者下边这种方式

        tabbar.composeBtnClick = { [weak self] in


            print("我会弹出登陆控制器\(self)")
        }

        setValue(tabbar, forKey: "tabBar")

        //统一设置字体颜色
        self.tabBar.tintColor = UIColor.orangeColor()


        self.addChildViewController(SFHomeTableViewController(), title: "首页", imgName: "tabbar_home")
        self.addChildViewController(SFMessageTableViewController(), title: "信息", imgName: "tabbar_message_center")
        self.addChildViewController(SFDiscoverTableViewController(), title: "发现", imgName: "tabbar_discover")
        self.addChildViewController(SFProfileTableViewController(), title: "我", imgName: "tabbar_profile")



    }


    func addChildViewController(childController: UIViewController, title: String, imgName: String ) {



        childController.tabBarItem.title = title

        childController.tabBarItem.image = UIImage(named: imgName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

        //设置单个文本选中颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)

        //设置单个文本大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14)], forState: UIControlState.Normal)


//        self.addChildViewController(UINavigationController.init(rootViewController: childController))
        self.addChildViewController(SFNvgViewController(rootViewController: childController))
    }









}
